﻿Public Class frmMasterGroupItem
    Dim dbBase As New dbMasterTable
    Dim frmCtrl As New FormControl
    Dim dsBase As DataSet
    Dim Var As New varDeclare
    Dim TypeAct As String

    Private Sub frmMasterGroupItem_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.WindowState = FormWindowState.Maximized
        dsBase = dbBase.getGroupItemList()
        TextBox(False, False)
        GridAndFind1.Initialize(dsBase, "Groups ID", ToolbarHeader1, Me, True)
        ToolbarHeader1.Iniliaze("Form : Groups Item", Me, Nothing, GridAndFind1.getDataGridView(), "Groups ID")
        Dim cmbItem As New List(Of comboItem)
        cmbItem.Add(New comboItem("Active", "A"))
        cmbItem.Add(New comboItem("Inactive", "I"))
        cmbStatus.DataSource = cmbItem
        cmbStatus.DisplayMember = "Text"
        cmbStatus.ValueMember = "Value"
    End Sub

    Private Sub Textbox(st As Boolean, clear As Boolean)
        cmbStatus.Enabled = st
        If (st) Then
            st = False
        Else : st = True
        End If
        txtGroupsCode.ReadOnly = st
        txtGroupsCode.BackColor = Color.White
        txtGroupsDesc.ReadOnly = st
        txtGroupsDesc.BackColor = Color.White
        GridAndFind1.Enabled = st
        If (clear) Then
            txtGroupsCode.Text = ""
            txtGroupsDesc.Text = ""
        End If
        If (TypeAct = "I") Then
            txtGroupsCode.ReadOnly = False
        Else : txtGroupsCode.ReadOnly = True
        End If
    End Sub

    Private Sub resetField()
        txtGroupsCode.BackColor = Color.White
        txtGroupsDesc.BackColor = Color.White
    End Sub

    Private Sub tsNew_Click(ByVal sender As Object) Handles ToolbarHeader1.tsNewClick
        TypeAct = "I"
        Textbox(True, True)
    End Sub

    Private Sub tsEdit_Click(ByVal sender As Object) Handles ToolbarHeader1.tsEditClick
        TypeAct = "U"
        Textbox(True, False)
    End Sub

    Private Sub tsDelete_Click(ByVal sender As Object) Handles ToolbarHeader1.tsDeleteClick
        If (txtGroupsCode.Text.Trim() <> "") Then
            TypeAct = "D"
            Dim result As String = dbBase.GroupsItemManagement(TypeAct, txtGroupsCode.Text.Trim(), txtGroupsDesc.Text.Trim(), cmbStatus.SelectedValue.ToString(), MDI.LoginID)
            If (result = "Success") Then
                frmCtrl.openChild(New frmMasterGroupItem, Me.ParentForm)
            Else : MessageBox.Show(result)
            End If
        Else : MessageBox.Show("Please Choose User First")
        End If
    End Sub

    Private Sub tsPrint_Click(ByVal sender As ToolbarHeader) Handles ToolbarHeader1.tsPrintClick
        ''Event 
    End Sub

    Private Sub tsSave_Click(ByVal sender As Object) Handles ToolbarHeader1.tsSaveClick
        Dim Status As Boolean
        If (IsNumeric(txtGroupsCode.Text.Trim()) = False) Then
            txtGroupsCode.BackColor = Color.LightPink
            Status = False
        End If
        If (Status) Then
            If (txtGroupsCode.Text.Trim() <> "" And txtGroupsDesc.Text.Trim() <> "" And cmbStatus.Text <> "") Then
                Dim result As String = dbBase.GroupsItemManagement(TypeAct, txtGroupsCode.Text.Trim(), txtGroupsDesc.Text.Trim(), cmbStatus.SelectedValue.ToString(), MDI.LoginID)
                If (result = "Success") Then
                    frmCtrl.openChild(New frmMasterGroupItem, Me.ParentForm)
                Else : MessageBox.Show(result)
                End If
            Else : MessageBox.Show("Please Fill All Field")
            End If
        End If
    End Sub

    Private Sub tsRefresh_Click(ByVal sender As Object) Handles ToolbarHeader1.tsRefreshClick
        frmCtrl.openChild(New frmMasterGroupItem, Me.ParentForm)
    End Sub

    Private Sub tsCancel_Click(ByVal sender As Object) Handles ToolbarHeader1.tsCancelClick
        frmCtrl.openChild(New frmMasterGroupItem, Me.ParentForm)
    End Sub

    Private Sub GridCellEnter_Click(ByVal sender As GridAndFind, KeyValue As String) Handles GridAndFind1.GridCellEnter
        Dim dvFind As DataView = New DataView(dsBase.Tables(0))
        dvFind.RowFilter = "[Groups ID] = '" & KeyValue & "'"
        txtGroupsCode.Text = dvFind.Item(0).Row("Groups ID").ToString()
        txtGroupsDesc.Text = dvFind.Item(0).Row("Group Desc").ToString()
        cmbStatus.SelectedValue = dvFind.Item(0).Row("Status")
    End Sub
End Class